package com.hmall.search.controller;

import com.hmall.api.dto.ItemDTO;
import com.hmall.search.domain.dto.AggregationDTO;
import com.hmall.search.domain.dto.ESPageDTO;
import com.hmall.search.domain.query.ItemPageQuery;
import com.hmall.search.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author ChenPi
 * @since 2025/03/24 09:33
 */
@Api(tags = "搜索服务")
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchController {

    private final SearchService searchService;

    @ApiOperation("商品分页查询")
    @GetMapping("/list")
    public ESPageDTO<ItemDTO> search(ItemPageQuery query) throws IOException {

        return searchService.search(query);
    }

    @ApiOperation("过滤条件聚合查询")
    @PostMapping("/filters")
    public AggregationDTO searchFilters(@RequestBody ItemPageQuery query) throws IOException {

        return searchService.searchFilters(query);
    }
}
